package org.nw.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.nw.constants.Constants;
import org.nw.jf.vo.FunRegisterPropertyVO;
import org.nw.jf.vo.UiReportTempletVO;
import org.nw.service.ServiceHelper;
import org.nw.vo.ParamVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * 报表模板的基础控制类
 * 
 * @author xuqc
 * @date 2013-7-29 下午01:27:23
 */
public abstract class AbsReportController extends AbsToftController {

	/**
	 * 报表节点首页的处理类，在菜单管理中，将对应文件名注册成report.html
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/index.html")
	public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
		ParamVO paramVO = getParamVO(request);
		// 获取模板数据
		String templetID = this.getService().getReportTempletID(paramVO);
		if(StringUtils.isBlank(templetID)) {
			throw new RuntimeException("没有分配报表模板！");
		}
		UiReportTempletVO templetVO = this.getService().getReportTempletVO(templetID);
		templetVO.setFunCode(paramVO.getFunCode());
		templetVO.setNodeKey(paramVO.getNodeKey());
		// 锁定条件
		templetVO.setLockingItemAry(this.getService().getLockingItemAry(paramVO));

		// 功能注册中定义的与生成单据相关的配置信息
		String sHeaderHeight = request.getParameter(FunRegisterPropertyVO._HEADERHEIGHT);
		try {
			if(sHeaderHeight != null) {
				templetVO.getFuncRegisterPropertyVO().setHeaderHeight(Integer.parseInt(sHeaderHeight));
			}
		} catch(Exception e) {
		}
		templetVO.getFuncRegisterPropertyVO().setHeaderSplit(
				Boolean.valueOf(request.getParameter(FunRegisterPropertyVO._HEADERSPLIT)));
		templetVO.getFuncRegisterPropertyVO().setWaterfallScene(
				Boolean.valueOf(request.getParameter(FunRegisterPropertyVO._WATERFALLSCENE)));
		templetVO.getFuncRegisterPropertyVO().setBtnArray(ServiceHelper.getBtnRegisterAry(paramVO));
		request.setAttribute(Constants.TEMPLETVO, templetVO);
		// 页面需要使用该moduleName
		request.setAttribute(Constants.MODULENAME, templetVO.getModuleName());
		return new ModelAndView(getFunHelpName(paramVO.getFunCode()));
	}
}
